		var Model = function (width,height,nodeCount){
		// VARS
			
		this.componentInteractions = [];
		this.componentInteractions[0] = new EntityComponentManager( new ConnectManager() );
		this.componentInteractions[1] = new EntityComponentManager( new VehicleManager() );
		this.componentInteractions[2] = new EntityComponentManager( new ArriveManager() );
		this.componentInteractions[3] = new EntityComponentManager( new WanderManager() );
		this.componentInteractions[4] = new EntityComponentManager( new PursueManager() );
		
		this.nodeCount = nodeCount;
		this.entities = [this.nodeCount];
		
		this.width = width;		
		this.height = height;
		
		this.view;
	
		this.setView = function(view){
		this.view = view;
		}
		this.getDimensions = function(){
		return {0:this.width,1:this.height};
		}
		this.decreaseConnections = function(){
			this.componentInteractions[0].getDomainManager().decreaseConnections();
			this.view.updateShownConnections(this.componentInteractions[0].getDomainManager().getConnections());
		}
		this.increaseConnections = function(){
			this.componentInteractions[0].getDomainManager().increaseConnections();
			this.view.updateShownConnections(this.componentInteractions[0].getDomainManager().getConnections());
		}
		this.setConnections = function(con){	
			this.componentInteractions[0].getDomainManager().setConnections(con);
		}
		
		this.update = function(tpf){
			this.calculate(tpf);
			this.doComponentInteractions(tpf);
			this.view.update(tpf,this.width,this.height,this.entities);
			document.getElementById("info").innerHTML = "<br>Fps:"+(1/tpf)+"<br>Tpf:"+tpf+"s";
		}
		this.doComponentInteractions = function(tpf){
			for(var i=0; i<this.componentInteractions.length; i++){
			this.componentInteractions[i].interact(tpf,this.entities);
			}
		}
		this.calculate = function(tpf){
			var dx;
			var dy;

			for(var i = 0;i<this.nodeCount;i++){
			connect = this.entities[i].connectComponent;
			spatial = this.entities[i].spatialComponent;
			connect.connectedEntitiesTracker = 0;
			connect.highestRad = 0;
			connect.distanceBetweenEnities = [];
			connect.connectedEntities = [];		
				for(var j = i+1;j<this.nodeCount;j++){
				dx = spatial.getX()-this.entities[j].spatialComponent.getX();
				dy = spatial.getY()-this.entities[j].spatialComponent.getY();			
				connect.distanceBetweenEntities[j] = dx*dx+dy*dy;
				}
			}

		}
		this.createPositions = function (){
			for(var i = 0;i<this.nodeCount;i++){
			this.entities[i] = new Entity();

			this.entities[i].spatialComponent = new SpatialComponent();
			this.entities[i].connectComponent = new ConnectComponent();
			this.entities[i].vehicleComponent = new VehicleComponent();
			
			this.entities[i].spatialComponent.setX( (this.width)*Math.random() );
			this.entities[i].spatialComponent.setY( (this.height)*Math.random() );
			
			this.componentInteractions[0].addEntity(this.entities[i]);
			this.componentInteractions[1].addEntity(this.entities[i]);
			}
				
		this.entities[0].arriveComponent = new ArriveComponent();		
		this.entities[0].arriveComponent.target = new Entity();
		this.entities[0].arriveComponent.weight = 100;
		this.entities[0].arriveComponent.slowing_distance = 150;
		this.entities[0].arriveComponent.target.spatialComponent=new SpatialComponent();
		this.entities[0].vehicleComponent.mass = 1;
		this.entities[0].vehicleComponent.max_force = 150;
		this.entities[0].vehicleComponent.max_speed = 150;

		/*
		this.entities[1].arriveComponent = new ArriveComponent();
		this.entities[1].arriveComponent.target = this.entities[0];
		this.entities[1].arriveComponent.weight = 100;
		this.entities[1].arriveComponent.slowing_distance = 150;
		*/
		this.entities[1].pursueComponent = new PursueComponent();
		this.entities[1].pursueComponent.target = this.entities[0];
		this.entities[1].pursueComponent.weight = 100;
		this.entities[1].pursueComponent.tuningFactor = 2.0;
		this.entities[1].vehicleComponent.mass = 1;
		this.entities[1].vehicleComponent.max_force = 150;
		this.entities[1].vehicleComponent.max_speed = 150;

		this.entities[2].wanderComponent = new WanderComponent();
		this.entities[2].vehicleComponent.mass = 1;
		this.entities[2].vehicleComponent.max_speed = 20;
		
		//this.componentInteractions[3].addEntity(this.entities[0]);	
		this.componentInteractions[3].addEntity(this.entities[2]);
		//this.componentInteractions[2].addEntity(this.entities[1]);						
		this.componentInteractions[2].addEntity(this.entities[0]);		
		this.componentInteractions[4].addEntity(this.entities[1]);		
		}
		this.moveDot = function(i,x,y){
		this.entities[i].arriveComponent.target.spatialComponent.position.elements[0]=x;
		this.entities[i].arriveComponent.target.spatialComponent.position.elements[1]=y;
		}		
	}